﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ImplementationInitialization;

namespace DataInitial
{
    public partial class ImportReportForm : Form
    {
        public ImportReportForm()
        {
            InitializeComponent();
        }

        public ImportReportForm(ImportCodificationResult result)
            : this()
        {
            //Codification Item Result.
            foreach (DataRow row in result.CodificationItemResult.Rows)
            {
                this.dgvCodificationItem.Rows.Add(
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_SUCCESS].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_ITEM_NAME].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_EXCEL_FILE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_TYPE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_EXCEL_SHEET].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_MESSAGE].ToString()
                    );
            }

            //Standard Item Result.
            foreach (DataRow row in result.StandardItemResult.Rows)
            {
                this.dgvStandardItem.Rows.Add(
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_SUCCESS].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_ITEM_NAME].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_EXCEL_FILE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_TYPE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_EXCEL_SHEET].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_MESSAGE].ToString()
                    );
            }

            //ExposureDraft Item Result.
            foreach (DataRow row in result.ExposureDraftItemResult.Rows)
            {
                this.dgvEDItem.Rows.Add(
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_SUCCESS].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_ITEM_NAME].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_EXCEL_FILE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_TYPE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_EXCEL_SHEET].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_MESSAGE].ToString()
                    );
            }

            //Codification Attachment Result.
            foreach (DataRow row in result.CodificationAttachmentResult.Rows)
            {
                this.dgvCodificationAttachment.Rows.Add(
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_SUCCESS].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_ITEM_NAME].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_TYPE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_MESSAGE].ToString()
                    );
            }

            //Standard Attachment Result.
            foreach (DataRow row in result.StandardAttachmentResult.Rows)
            {
                this.dgvStandardAttachment.Rows.Add(
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_SUCCESS].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_ITEM_NAME].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_TYPE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_MESSAGE].ToString()
                    );
            }

            //ExposureDraft Attachment Result.
            foreach (DataRow row in result.ExposureDraftAttachmentResult.Rows)
            {
                this.dgvEDAttachment.Rows.Add(
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_SUCCESS].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_ITEM_NAME].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_TYPE].ToString(),
                    row[ImplementationInitialization.Constants.ImportResultColumnNames.COL_MESSAGE].ToString()
                    );
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            ExportUtil export = new ExportUtil();
            switch (this.tabControl1.SelectedIndex)
            {
                case 0:
                    {
                        export.SaveAs(this.dgvCodificationItem);
                        break;
                    }
                case 1:
                    {
                        export.SaveAs(this.dgvCodificationAttachment);
                        break;
                    }
                case 2:
                    {
                        export.SaveAs(this.dgvStandardItem);
                        break;
                    }
                case 3:
                    {
                        export.SaveAs(this.dgvStandardAttachment);
                        break;
                    }
                case 4:
                    {
                        export.SaveAs(this.dgvEDItem);
                        break;
                    }
                case 5:
                    {
                        export.SaveAs(this.dgvEDAttachment);
                        break;
                    }
                default: { break; }
            }
        }
    }
}
